/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.telsoft.hms.lib.security.lang;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author HùngPV
 * thanbotbeo10@gmail.com, hungpv@telsoft.com.vn
 * Ngày tạo: 01/08/2014
 */

public abstract class AbstractThreadDoLoopWork extends com.telsoft.hms.lib.security.lang.AbstractThread {

    protected int interval = 500;

    public void setInterval(int delay) {
        if (isThreadRunning()) {
            this.stop();
            this.interval = delay;
            this.start();
        } else {
            this.interval = delay;
        }
    }

    @Override
    protected void _doSomething() {
        while (isThreadRunning()) {
            try {
                if (this.interval > 0) {
                    java.lang.Thread.sleep(this.interval);
                }
                doWork();
            } catch (Exception | Error ex) {
                Logger.getLogger(AbstractThreadDoLoopWork.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public abstract void doWork();
}
